<?php

namespace App\Models\V1;

use Illuminate\Database\Eloquent\Factories\HasFactory;

class UserPermission extends BaseModel
{
    use HasFactory;
    protected $connection;
    protected $table="user_permission";
    protected $fillable=['id','ulid','product','user_id','pid','menu_permission','game_permission'];

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->connection = config('database.connections.biqi_business.database');
    }


    // 定义修改器，将数组转换为 JSON
    public function setMenuPermissionAttribute($value)
    {
        $this->attributes['menu_permission'] = json_encode($value);
    }

    // 定义访问器，将 JSON 转换为数组
    public function getMenuPermissionAttribute($value)
    {
        return json_decode($value, true);
    }


    // 定义修改器，将数组转换为 JSON
    public function setGamePermissionAttribute($value)
    {
        $this->attributes['game_permission'] = json_encode($value);
    }


    // 定义访问器，将 JSON 转换为数组
    public function getGamePermissionAttribute($value)
    {
        return json_decode($value, true);
    }

}
